package com.baoming.web.action;

import java.io.InputStream;

import org.apache.struts2.ServletActionContext;
 
import com.baoming.container.ServiceContainer;
import com.baoming.domain.Singup;
import com.baoming.service.ISingupService; 
import com.baoming.tool.MatrixTool; 
import com.baoming.util.ServiceTool;
 
/**
 * 二维码下载 
 * @author Administrator
 *
 */
@SuppressWarnings("serial")
public class SingupQrcodeDownAction extends BaseAction {

	//指定要下载的文件的完整路径(路径名＋文件名)  
	private String inputPath; 
	private String fileName ; 
	private ISingupService singupService = (ISingupService) ServiceContainer.getService(ISingupService.SERVICE) ; 
	private String contentType ; 
	
	public String getContentType() {
		return contentType;
	}

	public void setContentType(String contentType) {
		this.contentType = "gif,xls";
	}

	/**
	 * 二维码下载 
	 * @return
	 */
	public String qrcode(){ 
		
		//得到比赛的id 
		String url = request.getParameter("url")+".do";    
		//生成二维码 
		String codePath = MatrixTool.create(url) ;   
		//设置下载路径
		this.setInputPath(codePath) ;  
		//设置生成的文件名
		this.setFileName(ServiceTool.getNowDate()+".gif") ; 
		
		return SUCCESS ; 
	}
	
	/**
	 * 名单间导出
	 * @param inputPath
	 */
	public String excel(){ 
		
		//得到报名的id
		String singupId = request.getParameter("id") ; 
		Singup singup = singupService.selectSingUpById(singupId) ; 
		
		//设置下载路径
		this.setInputPath(singup.getCodePath()) ; 
		
		//设置生成的文件名
		this.setFileName(ServiceTool.getNowDate()+".xls") ;  
		
		return SUCCESS ; 
	}

	public void setInputPath(String inputPath) {
		this.inputPath = inputPath;
	}

	/*  
     * 实现下载的Action类应该提供一个返回InputStream实例的方法，该方法对应在        
        <result.../>里的inputName属性值为targetFile  
	 */  
   public InputStream getTargetFile() throws Exception{   
	    
      return  ServletActionContext.getServletContext().getResourceAsStream(inputPath);   
   }   
   
	public String getInputPath() {
		return inputPath;
	}
 
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getFileName() {
		return fileName;
	}

	@Override
	public String add() {
		return null;
	}

	@Override
	public String edit() {
		return null;
	}

	@Override
	public String manager() {
		return null;
	}

	@Override
	public String remove() {
		return null;
	}

	@Override
	public String removeGroup() {
		return null;
	}

}